package cn.chuanw.wx.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.chuanw.wx.annotation.RequiresPermissionsDesc;
import cn.chuanw.core.util.RandomNumberUtil;
import cn.chuanw.core.util.ResponseUtil;
import cn.chuanw.db.domain.WRoomcostCollect;
import cn.chuanw.db.service.TenantService;
import cn.chuanw.db.service.WRoomCostCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/admin/roomCoust")
@Validated
public class wRoomCostCollectController {
	private final Log logger = LogFactory.getLog(wRoomCostCollectController.class);

	@Autowired
	private WRoomCostCollectService wRoomCostCollectService;
	@Autowired
	private TenantService tenantService;

	@RequiresPermissions("admin:roomCoust:list")
	@RequiresPermissionsDesc(menu = { "公寓管理", "水电收取信息" }, button = "查询")
	@GetMapping("/list")
	public Object list(String roomId, Integer costType, @RequestParam(defaultValue = "1") Integer page,
			@RequestParam(defaultValue = "10") Integer limit) {
		List<WRoomcostCollect> wRoomcostCollect = wRoomCostCollectService.querySelective(roomId, costType, page, limit);
		return ResponseUtil.okList(wRoomcostCollect);
	}

	@RequiresPermissions("admin:roomCoust:add")
	@RequiresPermissionsDesc(menu = { "公寓管理", "水电收取信息" }, button = "新增")
	@PostMapping("/add")
	public Object add(@RequestBody WRoomcostCollect wRoomcostCollect) {
		wRoomcostCollect.setId(RandomNumberUtil.getStringRandom(12));
		wRoomcostCollect.setCollectTime(LocalDateTime.now());
       wRoomCostCollectService.addWHouseInfo(wRoomcostCollect);
		return ResponseUtil.ok(wRoomcostCollect);
	}

	@RequiresPermissions("admin:roomCoust:update")
	@RequiresPermissionsDesc(menu = { "公寓管理", "水电收取信息" }, button = "修改")
	@PostMapping("/update")
	public Object update(@RequestBody WRoomcostCollect wRoomcostCollect) {
		wRoomCostCollectService.updateById(wRoomcostCollect);
		return ResponseUtil.ok(wRoomcostCollect);
	}
}
